package com.wang.jmonkey.ca.filter;

import com.wang.jmonkey.ca.property.SecurityProperty;
import org.springframework.boot.web.context.ConfigurableWebServerApplicationContext;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description
 * @Author HeJiawang
 * @Date 2021/5/8 16:35
 */
@Component
public class MobileSmsAuthenticationFilter extends AbstractAuthenticationFilter {

    private ConfigurableWebServerApplicationContext context;

    private SecurityProperty securityProperty;

    public MobileSmsAuthenticationFilter(SecurityProperty securityProperty , AuthenticationManager authenticationManager , ConfigurableWebServerApplicationContext context) {
        super(
                new AntPathRequestMatcher(
                        getLoginUrl(securityProperty , MobileSmsAuthenticationFilter.class),
                        getMethod(securityProperty , MobileSmsAuthenticationFilter.class)
                ),
                authenticationManager
        );

        this.context = context;
        this.securityProperty = securityProperty;
    }

    @Override
    protected Authentication authentication(HttpServletRequest request, HttpServletResponse response)
            throws AuthenticationException, IOException, ServletException {

        System.out.println("MobileSmsAuthenticationFilter");
        return null;
    }
}
